﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Data.Objects.DataClasses;
using System.Web.UI;

namespace BusinessApplication1.Web
{
    [ServiceContract(Namespace = "")]
    [SilverlightFaultBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class AuthorizationService
    {
        [OperationContract]
        public void DoWork()
        {
            // Добавьте здесь реализацию операции
            return;
        }

        [OperationContract]
        public void ImportClasses(SystemUser syUs)
        {

        }

        [OperationContract]
        public Triplet CheckUserCredentials(string login, string password)
        {
            using (K223DBEntities context = new K223DBEntities())
            {
                try
                {
                    SystemUser minedUser =  context.SystemUsers.FirstOrDefault(x => (x.Login == login && x.Password_Hash_ == password ));

                    if (minedUser != null)
                        return new Triplet(true, minedUser.Name, null);
                    else
                        return new Triplet(false, null, "Введенная пара логин/пароль не найдена");
                }
                catch (Exception ex)
                {
                    return new Triplet(false, null, ex.Message);
                }
            }
        }

        // Добавьте здесь дополнительные операции и отметьте их атрибутом [OperationContract]
    }
}
